<script>
    $(function() {
        UE.getEditor('content').addListener('contentchange', function() {
            this.sync();
        });
    });
</script>
<div class="SipeiMain_r fr">
   <h2 class="clearfix fonts_18 height45 fontc_444"><?php echo $this->title;?></h2>
   <div class="clearfix back_bgf border_3 border_c pr30 pt20 pb20 height32 fontc_666">
    <?php
		$form = $this->beginWidget('CActiveForm', array(
			'action' => $this->createUrl('add'),
			'method' => 'POST',
			'id' => 'myForm',
		 'htmlOptions'=>array('target'=>'ajax-frame')
		));
	?>
      <table class="fontc_666 height32">
        <tbody>
          <tr height="55">
            <td valign="top" width="125" align="right" class="pr5"><span class="pr5 fontc_orange_red">*</span>所属考试项目：</td>
            <td valign="top" width="370">
                  <span class="fl standard_select pt5 pr7 pb5 pl3 border_c border_3">
                    <span class="fl select_shelter">
                      <select class="fl fontc_666" id="exam_id" name="info[exam_id]">
                        <option value="0">请选择</option>
                        <?php if(!empty($info['examData'])): ?>
                            <?php foreach($info['examData'] as $ev): ?>
                          <option value="<?php echo $ev['exam_id'];  ?>"><?php echo $ev['exam_term_name'];  ?></option>
                        <?php endforeach; ?>
                        <?php endif; ?>
                      </select>
                    </span>
                  </span>
                  <div class="formValidator_tip">
                      <p id="exam_idTip" ></p>
                  </div>
            </td>
          </tr>
          <tr height="55">
            <td valign="top" align="right" class="pr5"><span class="pr5 fontc_orange_red">*</span>通知标题：</td>
            <td valign="top">
            	<input type="text" name="info[notice_name]" id="title" style="width:212px;" class="col3 pt5 pr10 pb5 pl10 height20 border_c border_3 fontc_666" />
            	<div class="formValidator_tip">
                    <p id="titleTip" ></p>
                </div>
            </td>
          </tr>
          <tr>
            <td valign="top" align="right" class="pr5" ><span class="pr5 fontc_orange_red">*</span>通知内容：</td>
            <td>
                <script> window.UEDITOR_CONFIG.initialFrameWidth = 550;</script>
                <textarea class="pt6 pr10 pb6" id="content" name="info[notice_comment]" ></textarea>
            </td>
          </tr>
          <tr>
            <td align="right" valign="top" class="pr5 pb20">是否显示：</td>
            <td class="pb20"><input type="checkbox" name="info[notice_status]" value='1'/></td>
          </tr> 
          <tr height="55">
            <td align="right" valign="top" class="pr5"><span class="pr5 fontc_orange_red">*</span>过期日期：</td>
            <td valign="top">
               <input type="text" name="info[expired]" value="" id="start_time"  onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'})" class="w140 pt5 pr5 pb5 pl10 height20 border_c border_3 fontc_666 SipeiTime" />
               <span id="path2"></span>
               <span id="name2"></span>
               <div class="formValidator_tip">
                    <p id="start_timeTip" ></p>
               </div>
            </td>
          </tr>       
          <tr height="55">
            <td align="right" valign="top" class="pr5">附件：</td>
            <td valign="top">            	
            	<input type="file" name="file_upload" id="m_files_upload"/>
                <div id="file_tip" style="display: none;"></div>
                <div id="some_file_queue">文件大小不要超过2M</div>
            </td>
          </tr>
          <tr>
            <td align="right" class="pr5 pb20"></td>
            <td class="pb20">
                <input type="submit" name="submit" value="保存" class="b_a_n border_3 back_bgfb w80 height32 fontc_FFF fonts_12 cursor mr10" />
                <input type="button" value="取消" onClick="history.back()" class="b_a_n border_3 back_bgb w80 height32 fontc_FFF fonts_12 cursor" />
            </td>			
          </tr>
        </tbody>
      </table>
<?php
		$this->endWidget();
	?>
   </div>
</div>
<iframe src='' style="display:none" name='ajax-frame'></iframe>
<script type="text/javascript">
     $("#m_files_upload").uploadify({
        'removeCompleted' : false,                 
        'buttonClass'   :'fl b_a_n border_3 back_bgfyg w80 height32 fontc_FFF fonts_12 text_align',
        'queueID'       : 'some_file_queue',
        'buttonImage'   : "",
        'buttonText'    : "浏览",
        'fileSizeLimit' : 2*1024,
        'height'        : 38,
        'width'         : 120,
        'queueSizeLimit': 3,
        'swf'           : site_url+'/statics/js/uploadify/uploadify.swf',
        'uploader'      : site_url+'<?php echo $this->createUrl('upload_ajax',array('uid'=>$userInfo['cuser']['id']));?>',
        'onUploadSuccess' : function(file, data, response) {
        	var ret = eval('('+data+')');
            if(data)
            {
            	var pathHtml = "<input type='hidden' name='path[]' value='"+ret.path+"'>";
            	var nameHtml = "<input type='hidden' name='pathname[]' value='"+ret.name+"'>";
            	$('#path2').append(pathHtml);
            	$('#name2').append(nameHtml);
            	
            }else{
               alert('文件上传失败');
            }
            
        },
        'onUploadProgress' : function(file, fileBytesLoaded, fileTotalBytes) {
            var percentage       = Math.round(fileBytesLoaded / fileTotalBytes * 100);
            $('#' + file.id).find('.m-file-progress-bar').css('width', percentage + '%');
            $('#' + file.id).find('.m-file-data').html(percentage + '%');
        },
        'onSelectError':function(file, errorCode, errorMsg){
            switch(errorCode) {
                case -100:
                    break;
               case -110:
                    alert("文件【"+file.name+"】\n超过2MB请重新选择");
                    break;
               case -120:
                    alert("文件【"+file.name+"】\n上传失败");
                    break;
                case -130:
                    alert("文件【"+file.name+"】不是系统定制的文件类型");
                    break;
            }
        },
        onError : function(file, errorCode, errorMsg, errorString) {
            
        }
    });

	$('#some_file_queue .cancel a').live("click",function(){
		$(this).parents(".uploadify-queue-item").fadeOut(200,function(){
			$(this).remove();
			
			var id = $(this).attr('id').substr(12,20);
			
			var name = $('#path2').children('input:eq('+id+')').val();
			var temp_name = $('#path2').children('input:eq('+id+')').val();
			$.get('<?php echo $this->createUrl('move_path');?>',{name:name,temp_name:temp_name},function(data){
					$('#path2').children('input:eq('+id+')').attr('name','temp');
					$('#name2').children('input:eq('+id+')').attr('name','temp');
			})	
			
		})
		return false;
	})
$(function(){
	$.formValidator.initConfig({formID:"myForm",theme:"126",submitOnce:false,
        onError:function(msg,obj,errorlist){
                $("#errorlist").empty();
                $.map(errorlist,function(msg){
                        $("#errorlist").append("<li>" + msg + "</li>")
                });
                alert(msg);
        },
        ajaxPrompt : '有数据正在异步验证，请稍等...'
	});

	/*考试项目验证*/
	$("#exam_id").formValidator({
		onShowText:"",
		onShow:"",
		onFocus:"",
		onCorrect:"选择正确"
	}).inputValidator({
		min:1,
		onError:"请选择考试项目"
	});

	/*标题验证*/
	$("#title").formValidator({
		onShowText:"请输入通知标题",
		onShow:"",
		onFocus:"",
		onCorrect:"输入正确",
		leftTrim:true,
		rightTrim:true
	}).inputValidator({
		min:1,
		max:20,
		onError:"通知标题长度在1-20之间(1到10个汉字)"
	});

	/*过期日期验证*/
	$("#start_time").formValidator({
		onShowText:"",
		onShow:"",
		onFocus:"",
		onCorrect:"选择正确"
	}).inputValidator({
		min:1,
		onError:"请选择过期日期"
	});


	
})
</script>
